home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / _lseek.c < prev    next >
C/C++ Source or Header  |  1994-03-30  |  1KB  |  66 lines

  1. RCS_ID_C="$Id: _lseek.c,v 1.3 1994/03/30 07:39:20 jraja Exp $";
  2. /*
  3.  * _lseek.c --- lseek() which knows sockets
  4.  *
  5.  * Author: jraja <Jarno.Rajahalme@hut.fi>
  6.  *
  7.  * This file is part of the AmiTCP/IP Network Support Library.
  8.  *
  9.  * Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>
  10.  *                  Helsinki University of Technology, Finland.
  11.  *                  All rights reserved.
  12.  *
  13.  * Created      : Thu Mar 17 21:54:44 1994 jraja
  14.  * Last modified: Wed Mar 30 10:25:26 1994 jraja
  15.  *
  16.  */
  17.  
  18. #include <ios1.h>
  19. #include <fcntl.h>
  20. #include <stdlib.h>
  21. #include <dos.h>
  22. #include <errno.h>
  23. #include <dos/dos.h>
  24. #include <proto/dos.h>
  25.  
  26. long
  27. __lseek(int fd, long rpos, int mode)
  28. {
  29.   struct UFB *ufb;
  30.   long        apos;
  31.  
  32.   /*
  33.    * Check for the break signals
  34.    */
  35.   __chkabort();
  36.   /*
  37.    * find the ufb *
  38.    */
  39.   if ((ufb = __chkufb(fd)) == NULL) {
  40.     errno = EINVAL;
  41.     return -1;
  42.   }
  43.   
  44.   _OSERR = 0;
  45.  
  46.   if (ufb->ufbflg & UFB_SOCK) {
  47.     errno = ESPIPE; /* illegal seek */
  48.     return -1;
  49.   }
  50.  
  51.   if ((apos = Seek(ufb->ufbfh, rpos, mode - 1)) == -1) {
  52.     _OSERR = IoErr();
  53.     errno = EIO;
  54.     return -1;
  55.   }
  56.   
  57.   switch (mode) {
  58.   case 0:
  59.     return rpos;
  60.   case 1:
  61.     return apos + rpos;
  62.   case 2:
  63.     return Seek(ufb->ufbfh, 0, 0);
  64.   }
  65. }
  66.